using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using DG.Tweening;
public class Button : MonoBehaviour
{
    
    Image image;//主人公图组件
    public int count;//代表第几个服装
    public GameObject sucess;//代表换装成功控件
    public GameObject panel;
    public GameObject[] select;//代表所有选中控件

    private int t;


    void Start(){
        t = 1;
        
    }
    void Update(){}

    //跳转到男宠界面
    public void gotoHandsomeMan(){
        SceneManager.LoadScene("HandsomeMan");
    }
    //跳转到换装界面
    public void gotoDress(){
        SceneManager.LoadScene("Dress");
    }
    //跳转到练级界面
    public void gotoLeveling(){
        SceneManager.LoadScene("Leveling");
    }
    //跳转到约会界面
    public void gotoAppointment(){
        SceneManager.LoadScene("Appointment");
    }
    // 跳转到主界面
    public void gotoMainGame(){
        SceneManager.LoadScene("MainGame");
    }
















    //还原按钮的点击事件
    public void restoreClothes(){
        //if (VariableDocument.GetInstance.isChangeClothes)
        //{
        for (int i = 0; i < 9; i++)
        {
            select[i].SetActive(false);
        }
        select[VariableDocument.GetInstance.ppr].SetActive(true);
        //}
        t = 1;
        VariableDocument.GetInstance.isChangeClothes = false;
        image = GameObject.Find("人物").GetComponent<Image>();
        VariableDocument.GetInstance.pr_characters = VariableDocument.GetInstance.ppr;
        image.sprite = Resources.Load<Sprite>(VariableDocument.GetInstance.clothes[VariableDocument.GetInstance.ppr]);
        Debug.Log(VariableDocument.GetInstance.pr_characters + ",   " + VariableDocument.GetInstance.ppr);
    }





    //保存按钮的点击事件
    public void SaveClothes(){
        //if (VariableDocument.GetInstance.isChangeClothes)
        //{
        //    for (int i = 0; i < 9; i++)
        //    {
        //        select[i].SetActive(false);
        //    }
        //}
        
        VariableDocument.GetInstance.isSaveClothes = true;
        if(VariableDocument.GetInstance.isChangeClothes){
            if(t == 1)
            {
                
                t = 2;
            }
            else
            {
                VariableDocument.GetInstance.ppr = VariableDocument.GetInstance.pr_characters;
            }

            //保存衣服后
            VariableDocument.GetInstance.pr_characters = VariableDocument.GetInstance.num;
            // 弹出换装成功
            sucess.SetActive(true);

            sucess.GetComponent<Transform>().DOMove(new Vector2(sucess.GetComponent<Transform>().position.x, sucess.GetComponent<Transform>().position.y + 20), 2f);
            Invoke("ImageDisappear", 2);
            Debug.Log(VariableDocument.GetInstance.pr_characters + ",   " + VariableDocument.GetInstance.ppr);
        }   
    }




























    
    //换装返回按钮的点击事件
    public void goback()
    {
        //Debug.Log(VariableDocument.GetInstance.isChangeClothes);
        //Debug.Log(VariableDocument.GetInstance.isSaveClothes);
        //if (VariableDocument.GetInstance.isChangeClothes)
        //{
        //    if (VariableDocument.GetInstance.isSaveClothes)
        //    {
        //        SceneManager.LoadScene("MainGame");
        //    }
        //    else
        //    {
        //        //弹框
        //        VariableDocument.GetInstance.figure_of_characters = VariableDocument.GetInstance.pr_characters;
        //        //panel.SetActive(true);
        //    }
        //}
        //else
        //{
        VariableDocument.GetInstance.figure_of_characters = VariableDocument.GetInstance.pr_characters;
        SceneManager.LoadScene("MainGame");
        Debug.Log(VariableDocument.GetInstance.figure_of_characters);
        //}
    }























    //保存按钮
    public void SaveCloths()
    {
        VariableDocument.GetInstance.pr_characters = VariableDocument.GetInstance.figure_of_characters;
        SceneManager.LoadScene("MainGame");
        
    }
    //取消按钮
    public void CacelCloths()
    {
        VariableDocument.GetInstance.figure_of_characters = VariableDocument.GetInstance.pr_characters;
        SceneManager.LoadScene("MainGame");

    }



    // 弹出换装成功n秒后消失
    private void ImageDisappear()
    {
        sucess.SetActive(false);
        sucess.GetComponent<Transform>().DOMove(new Vector2(sucess.GetComponent<Transform>().position.x, sucess.GetComponent<Transform>().position.y - 20), 1f);
        VariableDocument.GetInstance.isChangeClothes = false;
    }

}
